$(function () {

    $.util.get($.util.getRequestJson('/dict/findByGroupKey.json'), {groupKey: "commtityType"}, function (data) {
        $('#commtityTypeVerify').combobox({
            method: 'post',
            panelHeight: 200,//设置为固定高度，combobox出现竖直滚动条
            valueField: 'dictKey',
            textField: 'dictText',
            data: data.rows,
            multiple: true
        });
    });


    $("#detail").ueditor({
        height: 250,
        template: false,
        toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', '|', 'simpleupload', '|', 'horizontal', 'date', 'time'
        ]]
    })

    var accept = {
        title: 'Images',
        extensions: 'gif,jpg,jpeg,bmp,png',
        mimeTypes: 'image/*'
    };
    $('#commName').text('商品图片');
    $("#attachedFile").webuploader({
        // 文件接收服务端。
        server: $.util.getRequestJson('/json/uploader.upload.json'),
        accept: accept,
        auto: true,
        fileNumLimit: 3 //限制多文件上传的个数
    });


    // $('input[type=radio][name=isQuality]').change(function () {
    //     if (this.value == '1') {
    //         $('#commQuality').removeAttr("style");
    //     } else if (this.value == '0') {
    //         $('#commQuality').attr("style", "display: none");
    //     }
    // });
    // var acceptQuality = {
    //     title: 'Image',
    //     extensions: 'gif,jpg,jpeg,bmp,png',
    //     mimeTypes: 'image/*'
    // };
    // $('#commNameQuality').text('精品专区图片');
    // $("#attachedFileQuality").webuploader({
    //     // 文件接收服务端。
    //     server: $.util.getRequestJson('/json/uploader.upload.json'),
    //     accept: acceptQuality,
    //     auto: true,
    //     fileNumLimit: 1 //限制多文件上传的个数
    // });

    $('input[type=radio][name=isDiscount]').change(function () {
        if (this.value == '1') {
            $('#disPrice').removeAttr("style");
            $('#disScore').removeAttr("style");
        } else if (this.value == '0') {
            $('#disPrice').attr("style", "display: none");
            $('#disScore').attr("style", "display: none");
        }
    });
    $('input[type=radio][name=verifyResult]').change(function () {
        if (this.value == '1') {
            $('#quality').removeAttr("style");
            $('#home').removeAttr("style");
            var isQualityVal = $('input[name="isQuality"]:checked').val();
            if (isQualityVal == 1) {
                $('#commQuality').removeAttr("style");
            }
        } else if (this.value == '0') {
            $('#quality').attr("style", "display: none");
            $('#home').attr("style", "display: none");
            $('#commQuality').attr("style", "display: none");
        }
    });


    var id = $.util.getRequest("id");
    if (id) {
        var url = $.util.getRequestJson('/json/productManage.productDetail.json');
        $.util.get(url, {id: id}, function (data) {
            setTimeout(function () {
                var dictKeyBack = data.data.dictKey;
                var isDiscount = data.data.isDiscount;
                var isQuality = data.data.isQuality;
                var verifyResult = data.data.verifyResult;
                if (isDiscount == 1) {
                    $('#disPrice').removeAttr("style");
                    $('#disScore').removeAttr("style");
                }
                if (verifyResult == null) {
                    data.data.verifyResult = 1;
                } else if (verifyResult == 0) {
                    $('#quality').attr("style", "display: none");
                    $('#home').attr("style", "display: none");
                }
                if (isQuality == 0) {
                    $('#commQuality').attr("style", "display: none");
                }

                $('#verifyProduct').form('load', data.data);
                if (dictKeyBack) {
                    var dictKey = dictKeyBack.split(",");
                    $("#commtityTypeVerify").combobox('setValues', dictKey);
                }
            }, 100);
        });
    }
})